<?php
class Entidade extends AppModel {
	var $name = 'Entidade';
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'Genero' => array(
			'className' => 'Genero',
			'foreignKey' => 'genero_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
        'Paise' => array(
			'className' => 'Paise',
			'foreignKey' => 'morada_pais',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Provincia' => array(
			'className' => 'Provincia',
			'foreignKey' => 'provincia_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Distrito' => array(
			'className' => 'Distrito',
			'foreignKey' => 'distrito_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'GrauAcademico' => array(
			'className' => 'GrauAcademico',
			'foreignKey' => 'grau_academico_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);

	var $hasMany = array(
		'Candidato' => array(
			'className' => 'Candidato',
			'foreignKey' => 'entidade_id',
			'dependent' => false,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'exclusive' => '',
			'finderQuery' => '',
			'counterQuery' => ''
		)
	);


	var $hasAndBelongsToMany = array(
		'Empresa' => array(
			'className' => 'Empresa',
			'joinTable' => 'empresas_entidades',
			'foreignKey' => 'entidade_id',
			'associationForeignKey' => 'empresa_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		),
		'Area' => array(
			'className' => 'Area',
			'joinTable' => 'entidades_areas',
			'foreignKey' => 'entidade_id',
			'associationForeignKey' => 'area_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		),
		'Idioma' => array(
			'className' => 'Idioma',
			'joinTable' => 'entidades_idiomas',
			'foreignKey' => 'entidade_id',
			'associationForeignKey' => 'idioma_id',
			'unique' => true,
			'conditions' => '',
			'fields' => '',
			'order' => '',
			'limit' => '',
			'offset' => '',
			'finderQuery' => '',
			'deleteQuery' => '',
			'insertQuery' => ''
		)
	);
    
    var $validate = array(
    'email' => array(
        'rule' => 'isUnique',
        'message' => 'This username has already been taken.'
    )
);

	function afterFind($results) {
	
	foreach ($results as $key => $val) {
		if (isset($val['Entidade']['name'])) {
			$results[$key]['Entidade']['primeiro_nome'] = $val['Entidade']['name'];
			$results[$key]['Entidade']['ultimo_nome'] = $val['Entidade']['name'];
		}
	}
	return $results;
}

}
